import { exportUrl } from "@/api/fqc/mesFqcTask"
import { getDict } from "@/api/common"
import { uniqueKey, checkStr } from "@/utils/judge"
// const _this = null;

// export const sendThis = (that) => {
//   _this = that;
// };
// 列表头按钮配置
export const operateList = [
  {
    name: $i18n.t("common.export"),
    type: "primary",
    icon: "el-icon-download",
    handleName: "export", //点击时返回的标识
    url: exportUrl
    //auth: "auth:operlog:export", //权限字段
  },
  {
    name: $i18n.t("common.add"),
    type: "primary",
    icon: "el-icon-circle-plus-outline",
    handleName: "add" // 点击时返回的标识
    // auth: "auth:user:add", //权限字段
  },
  {
    name: $i18n.t("common.delete"),
    type: "danger",
    icon: "el-icon-delete",
    handleName: "delete",
    isMultiple: true // isSingle 表示必须选择一项//isMultiple: true, // 表示必须多选
    // auth: "auth:user:delete", //权限字段
  }
]
// 行末按钮配置
export const rowConfig = [
  {
    name: $i18n.t("common.details"),
    type: "primary",
    class: "row-btn-primary",
    handleName: "show" //点击时返回的标识
  },
  {
    name: $i18n.t("common.edit"),
    type: "primary",
    class: "row-btn-primary",
    handleName: "edit" //点击时返回的标识
  },
  // {
  //   name: $i18n.t("mesFqcTask.batchAdd"),
  //   type: "primary",
  //   class: "row-btn-primary",
  //   handleName: "multiAdd" //点击时返回的标识
  // }
]
// 搜索条件配置
export const searchConfig = {
  inline: true,
  formDesc: {
    resultCode: {
      type: "input",
      label: $i18n.t("mesFqcTask.resultCode")
    },
    orderCode: {
      type: "input",
      label: $i18n.t("mesFqcTask.productWorkOrder")
    },
    status: {
      type: "select",
      label: $i18n.t("common.status"),
      prop: {
        value: "value",
        text: "description"
      },
      options: async (data) => {
        const list = await getDict("qms_inspection_result_status")
        return list.data.result
      }
    },

    prodCode: {
      type: "input",
      label: $i18n.t("mesFqcTask.productCode")
    },
    prodName: {
      type: "input",
      label: $i18n.t("mesFqcTask.productName")
    }
  }
}
// 新增/删除表单配置
export const formDesc = {
  data() {
    const that = this

    var validatePass = (rule, value, callback) => {
      setTimeout(() => {
        if (value === undefined || value === null) {
          callback()
        } else {
          if (!checkStr(value, "english-number-")) {
            callback(new Error($i18n.t("mesFqcTask.rule11")))
          } else {
            callback()
          }
        }
      }, 100)
    }
    return {
      formDescDialogs: {
        span: 24,
        disabled: true,
        isShowSubmitBtn: false,
        rules: {
          resultCode: [{ validator: validatePass, trigger: ["change", "blur"] }]
        },
        formDesc: {
          resultCode: {
            type: "input",
            label: $i18n.t("mesFqcTask.resultCode"),
            layout: 12,
            required: false,
            disabled: (data) => {
              return !!data.codeStrategy || !!data.id
            }
          },
          planCode: {
            type: "input",
            label: $i18n.t("mesFqcTask.planCode"),
            layout: 12,
            required: false,
            disabled: true
          },
          orderCode: {
            type: "input",
            label: $i18n.t("mesFqcTask.productWorkOrder"),
            layout: 12,
            required: true
          },
          prodCode: {
            type: "input",
            label: $i18n.t("mesFqcTask.productCode"),
            layout: 12,
            required: false,
            disabled: true
          },
          prodName: {
            type: "input",
            label: $i18n.t("mesFqcTask.productName"),
            layout: 12,
            required: false,
            disabled: true
          },
          assignmentPlanDate: {
            type: "date",
            label: $i18n.t("mesFqcTask.assignmentPlanDate"),
            layout: 12,
            required: true,
            attrs: {
              valueFormat: "yyyy-MM-dd"
            }
          },
          // templateCode: {
          //     type: "input",
          //     label: "模板编码",
          //     layout:  12,
          //     required: false,
          // },
          // templateName: {
          //     type: "input",
          //     label: "模板名称",
          //     layout:  12,
          //     required: false,
          // },
          // templateType: {
          //     type: "input",
          //     label: "模板类型--数据字典（首件、末件、巡检、抽样）",
          //     layout:  12,
          //     required: false,
          // },
          // status: {
          //     type: "input",
          //     label: "状态：0-未开始、1-进行中、2-完成、3-异常完成",
          //     layout:  12,
          //     required: false,
          // },
          // startTime: {
          //   type: "datetime",
          //   label: "开始时间",
          //   layout: 12,
          //   required: false,
          //   attrs: {
          //     valueFormat: "yyyy-MM-dd HH:mm:ss",
          //   },
          // },
          // endTime: {
          //   type: "datetime",
          //   label: "结束时间",
          //   layout: 12,
          //   required: false,
          //   attrs: {
          //     valueFormat: "yyyy-MM-dd HH:mm:ss",
          //   },
          // },
          // result: {
          //     type: "input",
          //     label: "检验结果：0-待检测、1-合格、2-不合格",
          //     layout:  12,
          //     required: false,
          // },
          // quantity: {
          //     type: "number",
          //     label: "检验数量",
          //     layout:  12,
          //     required: false,
          // },
          // imagePath: {
          //     type: "input",
          //     label: "图片地址",
          //     layout:  12,
          //     required: false,
          // },
          remark: {
            type: "input",
            label: $i18n.t("common.remark"),
            layout: 12,
            required: false
          },

          mesFqcTaskDetailList: {
            label: "",
            layout: 24,
            type: "table-editor",
            attrs: {
              // 上方,按钮,render
              topBtnRender: (h, solt) => {
                return (
                  <el-button
                    type="primary"
                    onClick={() => {

                      that.addList()
                    }}>
                    {$i18n.t("common.add")}
                  </el-button>
                )
              },
              // 校检规则
              // rules: {
              //   lineNum: { required: true, message: "请输入行号" },
              //   count: { required: true, message: "请输入数量" },
              // },
              isShowAdd: false,
              // 表格列
              //   字段已对完
              columns: [
                {
                  // el-table-column 的属性
                  type: "index",
                  width: 50
                },
                {
                  prop: "barcode",
                  label: $i18n.t("mesFqcTask.boxCode"),
                  minWidth: 300,
                  showOverflowTooltip: true
                },
                {
                  prop: "prodCode",
                  label: $i18n.t("mesFqcTask.modelCode"),
                  minWidth: 120,
                  showOverflowTooltip: true
                },
                {
                  prop: "prodName",
                  label: $i18n.t("mesFqcTask.modelName"),
                  minWidth: 180,
                  showOverflowTooltip: true
                },
                {
                  prop: "seriesCode",
                  label: $i18n.t("mesFqcTask.seriesCode"),
                  minWidth: 120,
                  showOverflowTooltip: true
                },
                {
                  prop: "seriesName",
                  label: $i18n.t("mesFqcTask.seriesName"),
                  minWidth: 120,
                  showOverflowTooltip: true
                },
                {
                  prop: "count",
                  label: $i18n.t("mesFqcTask.volume"),
                  // minWidth: 80,
                  showOverflowTooltip: true
                },
                // {
                //   prop: "planBeginDate",
                //   label: "计划开始时间",
                //   width: 180,
                // },
                // {
                //   prop: "planEndDate",
                //   label: "计划结束时间",
                //   width: 180,
                // },
                // {
                //   prop: "barcodePrintTemp",
                //   label: "打印条码模板名称",
                // },

                // {
                //   prop: "barcodeFront",
                //   label: "条码前缀",
                // },
                {
                  prop: "lineName",
                  label: $i18n.t("common.lineName"),
                  minWidth: 130,
                  showOverflowTooltip: true
                },
                {
                  prop: "lineCode",
                  label: $i18n.t("common.lineCode"),
                  minWidth: 80,
                  showOverflowTooltip: true
                }
                // {
                //   prop: "isPrint",
                //   label: " 打印标识 1是 0否",
                // },
                // {
                //   prop: "isSubmitted",
                //   label: " 报工标识 1是 0否",
                // },
                // {
                //   prop: "factoryCode",
                //   label: "工厂编码",
                // },
              ],

              // 新行默认值
              newColumnValue: {
                lineNum: 0,
                count: 0
              }
            }
          }
        }
      }
    }
  }
}
